package com.presto.directo.base

import ai.advance.liveness.lib.*
import android.app.*
import android.os.Bundle
import com.appsflyer.*
import com.facebook.*
import com.orhanobut.logger.*
import com.presto.directo.BuildConfig
import com.presto.directo.utils.*

class XApplication : Application(), Application.ActivityLifecycleCallbacks {

    override fun onCreate() {
        super.onCreate()
        application = this
        registerActivityLifecycleCallbacks(this)
        SPUtil.context = this
        if (BuildConfig.DEBUG) {
            Logger.addLogAdapter(AndroidLogAdapter())
        }
        if (Af.KEY.isNotEmpty()) {
            AppsFlyerLib.getInstance().init(Af.KEY, object : AppsFlyerConversionListener {
                override fun onConversionDataSuccess(map: MutableMap<String, Any>?) {}
                override fun onConversionDataFail(s: String?) {}
                override fun onAppOpenAttribution(attribution: MutableMap<String, String>?) {}
                override fun onAttributionFailure(s: String?) {}
            }, this)
            AppsFlyerLib.getInstance().start(this)
        }
        FacebookSdk.setIsDebugEnabled(BuildConfig.DEBUG)
        FacebookSdk.addLoggingBehavior(LoggingBehavior.APP_EVENTS)
        GuardianLivenessDetectionSDK.init(this, "7b99eda0c22ca6b4", "1b2766c202ea9d0b", Market.Mexico)
    }

    companion object {
        lateinit var application: Application
    }

    override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?) {
        activity.add()
    }

    override fun onActivityStarted(activity: Activity) {

    }

    override fun onActivityResumed(activity: Activity) {

    }

    override fun onActivityPaused(activity: Activity) {

    }

    override fun onActivityStopped(activity: Activity) {

    }

    override fun onActivitySaveInstanceState(activity: Activity, outState: Bundle) {

    }

    override fun onActivityDestroyed(activity: Activity) {
        activity.remove()
    }

}